package com.hdu.util;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;

public class HttpUtils {

    private static final RestTemplate REST_TEMPLATE = new RestTemplate();

    public static String doPost(String url, String postBody) throws IOException {
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<String> entity = new HttpEntity<>(postBody, headers);
        ResponseEntity<String> response = REST_TEMPLATE.postForEntity(
                url,
                entity,
                String.class
        );
        return response.getBody();
    }
}